
import DB.Table;
import java.awt.Color;
import java.awt.Cursor;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yuval
 */
public class ResultFrame extends javax.swing.JFrame {

    //private DefaultTableModel bornInModel;
    private MainFrame parent;
    /**
     * Creates new form ResultFrame
     */
    public ResultFrame(MainFrame parent, Table res, String query) {
        initComponents();
        //bornInModel = (DefaultTableModel) bornInResults.getModel();
        this.theQuery.setText(query);
        this.parent = parent;
        String data[][] = {};
        String col[] = new String[res.getTitles().size() + 1];
        for (int i = 0; i < col.length - 1; i++)
            col[i] = res.getTitles().elementAt(i);
        col[col.length - 1] = "Probability";
        DefaultTableModel model = new DefaultTableModel(data,col);
        bornInResults.setModel(model);
        parent.setEnabled(false);
        this.setLocationRelativeTo(null);
        this.setVisible(true);

        Vector<Vector<String>> content = res.getContent();
        for(Vector<String> tuple : content){
            model.addRow(tuple);
        }
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        bornInResults = new javax.swing.JTable();
        returnBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        checkReult = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        theQuery = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Results");

        bornInResults.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Year", "Probability"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(bornInResults);
        bornInResults.getColumnModel().getColumn(0).setResizable(false);
        bornInResults.getColumnModel().getColumn(1).setResizable(false);
        bornInResults.getColumnModel().getColumn(2).setResizable(false);

        returnBtn.setText("Return");
        returnBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                returnBtnMouseClicked(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("The Results");

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/reddit.png"))); // NOI18N

        checkReult.setForeground(new java.awt.Color(0, 0, 255));
        checkReult.setText("check results");
        checkReult.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                checkReultMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                checkReultMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                checkReultMouseExited(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/wikipediaIconSm.png"))); // NOI18N

        theQuery.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(6, 6, 6)
                                .addComponent(checkReult)
                                .addGap(79, 79, 79)
                                .addComponent(returnBtn))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(117, 117, 117)
                                .addComponent(jLabel1)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(theQuery, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(0, 18, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(theQuery, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(returnBtn)
                            .addComponent(checkReult))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void returnBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_returnBtnMouseClicked
       this.setVisible(false);
       parent.clearTextFields();
       parent.setEnabled(true);
    }//GEN-LAST:event_returnBtnMouseClicked

    private void checkReultMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkReultMouseClicked
        BareBonesBrowserLaunch.openURL("http://en.wikipedia.org/wiki/Main_Page");
    }//GEN-LAST:event_checkReultMouseClicked

    private void checkReultMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkReultMouseEntered
        checkReult.setForeground(Color.red);
        Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
        setCursor(handCursor);
    }//GEN-LAST:event_checkReultMouseEntered

    private void checkReultMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkReultMouseExited
        checkReult.setForeground(Color.blue);
        Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR);
        setCursor(normalCursor);
    }//GEN-LAST:event_checkReultMouseExited


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable bornInResults;
    private javax.swing.JLabel checkReult;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton returnBtn;
    private javax.swing.JLabel theQuery;
    // End of variables declaration//GEN-END:variables
}
